<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <#include "../head.ftl">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="fileInfoForm">
            <div class="layui-form-item">
                <label for="nickName" class="layui-form-label">
                    <span class="x-red">*</span>标题
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="title" name="title"
                           value="${konwledge.title?if_exists}" required=""
                           lay-verify="title"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>知识分类</label>
                <div class="layui-input-inline">
                    <select id="shipping" name="knowledge" class="valid">
                        <option value="0"<#if konwledge.knowledge == 0>selected</#if>>一般知识</option>
                        <option value="1"<#if konwledge.knowledge == 1>selected</#if>>行业知识</option>
                        <option value="2"<#if konwledge.knowledge == 2>selected</#if>>专业知识</option>
                        <option value="3"<#if konwledge.knowledge == 3>selected</#if>>百科知识</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">资料内容描述</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" name="knowledgeDesc"
                              class="layui-textarea">${konwledge.knowledgeDesc?if_exists}</textarea>
                </div>
            </div>
            <input id="fid" name="fid" type="hidden" value="${konwledge.fid?if_exists}"/>
            <input id="filePath" name="filePath" type="hidden" value="${konwledge.filePath?if_exists}"/>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchTest" lay-text="通过|未通过">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button class="layui-btn" lay-filter="add" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer'],
            function () {
                $ = layui.jquery;
                var form = layui.form,
                        layer = layui.layer;

                //自定义验证规则
                form.verify({
                    nickName: function (value) {
                        if (value.length < 2) {
                            return '昵称至少得2个字符啊';
                        }
                    },
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    repass: function (value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    }
                });

                form.on('submit(add)',
                        function (data) {
                            var param = $("#fileInfoForm").serializeArray();
                            $.post("${basePath}/file/edit", param, function (rs) {
                                //string 转 json
                                var obj = eval('(' + rs + ')');
                                if (obj.status == 200) {
                                    layer.alert("保存成功", {icon: 6},
                                            function () {
                                                //关闭当前frame
                                                xadmin.close();
                                                // 可以对父窗口进行刷新
                                                xadmin.father_reload();
                                            });
                                } else {
                                    layer.alert(obj.message);
                                };
                            })
                            return false;
                        });

            });
</script>
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
</body>

</html>
